package exam.dfs;

/**
 * @author shenenlu 2021年06月05日 上午01:19:14
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * 寻找最大的正方形子矩阵 的面积
 *
 * 样例输入
 * 3
 * 110
 * 111
 * 110
 *
 * 输出:4
 *
 * 8
 * 1010111111
 * 0000000111
 * 1010110111
 * 0000111111
 * 1010111111
 * 0000001111
 * 1010111111
 * 0000110001
 *
 * 输出:16
 *
 * @author shenenlu 2021年06月04日 下午22:47:42
 */
public class FindSubMatrix {


    public static void main(String[] args) throws IOException {

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        int m = Integer.parseInt(bufferedReader.readLine());
        String[] inputMatrixStrArr = new String[m];
        for(int i=0; i<m; i++){
            inputMatrixStrArr[i] = bufferedReader.readLine();
        }
        int n = inputMatrixStrArr[0].toCharArray().length;

        int[][] matrix = new int[m][n];
        for( int i=0; i<m ;i++){
            char[] chars = inputMatrixStrArr[i].toCharArray();
            for(int j=0;j< n; j++){
                matrix[i][j] = chars[j]-'0';
            }
        }
        SearchMatrixHelper searchMatrixHelper = new SearchMatrixHelper(matrix, m,n);
        searchMatrixHelper.searchMatrix(0, 1);

        int i = searchMatrixHelper.searchMaxSuccessResult;
        System.out.println(i*i);
    }

    static class SearchMatrixHelper{
        int[][] matrix;
        int m;
        int n;
        int searchMaxLevel;
        int searchMaxSuccessResult;

        public SearchMatrixHelper(int[][] matrix, int m, int n) {
            this.matrix = matrix;
            this.m = m;
            this.n = n;
            this.searchMaxLevel = Math.min(m,n);
            this.searchMaxSuccessResult = 0;
        }

        public void searchMatrix(int index, int searchLevel) {
            if( index > m*n ){
                return;
            }
            if( searchLevel > searchMaxLevel ){
                return;
            }
            int x = index / n;
            int y = index - x*n;
            if( x + searchMaxSuccessResult > m && y + searchMaxSuccessResult > n ){
                return;
            }

            if(checkSubMatrix(x, y , searchLevel)){
                this.searchMaxSuccessResult = Math.max(this.searchMaxSuccessResult, searchLevel);
                searchMatrix(index, searchLevel+1);
            }
            searchMatrix(index+1, searchLevel);
        }

        private boolean checkSubMatrix(int x, int y, int searchLevel) {
            if(searchLevel == 1){
                return true;
            }
            if( x + searchLevel > m || y + searchLevel > n ){
                return false;
            }
            int value= matrix[x][y];
            for( int i=x; i< x + searchLevel; i++){
                for(int j=y; j< y + searchLevel; j++){
                    if( matrix[i][j] != value){
                        return false;
                    }
                }
            }
            return true;
        }

    }





}

